package com.dldata.display.control.pages;

import com.dldata.display.entity.SysDtwyZbbEntity;
import com.dldata.display.entity.SysRoleMenuEntity;
import com.dldata.display.service.System.SysDtwyZbbService;
import com.dldata.display.service.System.SysUserPowerCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Created by 吴岳峰 on 2017/07/11.
 */
@Controller
@RequestMapping("/V_SysDtwyZbb")
public class V_SysDtwyZbbController {

    @Autowired
    private SysUserPowerCheckService sysUserPowerCheckService;
    @Autowired
    private SysDtwyZbbService sysDtwyZbbService;

    @RequestMapping("/toList")
    public String toList(@CookieValue(value = "userid", defaultValue = "") String userid,
                         @RequestParam(value = "menuCode", defaultValue = "") String menuCode,
                         @CookieValue(value = "syscode",defaultValue = "")String sysCode,Model model){
        SysRoleMenuEntity roleMenuEntity = new SysRoleMenuEntity();
        List<SysRoleMenuEntity> sysRoleMenuEntityList = sysUserPowerCheckService.checkUserPower(menuCode, userid,sysCode);
        if (sysRoleMenuEntityList.size() > 0) {
            roleMenuEntity = sysRoleMenuEntityList.get(0);
            model.addAttribute("roleMenu", roleMenuEntity);
        }
        return "v_SysDtwyZbbList";
    }

    @RequestMapping("/toEdit")
    public String toEdit(String ks,String id ,String rq, Model model){


        model.addAttribute("ks",ks);
        if(id!=null&&!id.equals("")){
            SysDtwyZbbEntity sysDtwyZbbEntity =  sysDtwyZbbService.findOne(id);
            model.addAttribute("entity",sysDtwyZbbEntity);
            model.addAttribute("rq",sysDtwyZbbEntity.getRq().toString().substring(0,10));
            model.addAttribute("ks",sysDtwyZbbEntity.getKsId());
        }
        return "v_SysDtwyZbbEdit";
    }

}
